﻿using AutoMapper;
using B.S.DataBase.MyProject.Domain.Procurements;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure.Interface;
using MediatR;
using T.E.ERP.Write.API.Applicantions.Command.ProcurementsCommand;

namespace T.E.ERP.Write.API.Applicantions.CommandHandler.ProcurementsCommandCommand
{
    /// <summary>
    /// 采购退货单命令处理
    /// </summary>
    public class UpdPurchaseArrivalHandler : IRequestHandler<UpdPurchaseArrivalCommand, APIResult<object>>
    {
        private readonly IBaseRepository<Preturnorder> _purchaseArrival;
        private readonly IMapper mapper;

        public UpdPurchaseArrivalHandler(IBaseRepository<Preturnorder> purchaseArrival, IMapper mapper)
        {
            _purchaseArrival = purchaseArrival;
            this.mapper = mapper;
        }
        public async Task<APIResult<object>> Handle(UpdPurchaseArrivalCommand request, CancellationToken cancellationToken)
        {
            APIResult<object> result = new APIResult<object>();
            result.Code = APIEnum.修改成功;
            result.Msg = APIEnum.修改成功.ToString();
            var entity = mapper.Map<Preturnorder>(request);
            await _purchaseArrival.Update(entity);
            return await Task.FromResult(result);
        }
    }
}
